package com.xb.cloud.gateway.client;

/**
 * 
 * @ClassName: ReturnUtils
 * @Description:服务调用返回码工具类
 * @author: 鲜备科技
 * @date: 2017年12月25日 上午10:59:00
 * 
 * @Copyright: 2017 www.xianbeitech.com Inc. All rights reserved.
 *
 */
public class ReturnUtils {

	public static boolean isSuccess(RtnInfo rtnInfo) {
		if (rtnInfo.getRtnCode().equals(ReturnCodes.SUCCESS.getCode())) {
			return true;
		}
		return false;
	}

	public static boolean isError(RtnInfo rtnInfo) {
		if (rtnInfo.getRtnCode().equals(ReturnCodes.SUCCESS.getCode())) {
			return false;
		}
		return true;
	}

	public static RtnInfo success() {
		RtnInfo info = new RtnInfo();
		info.setRtnCode(ReturnCodes.SUCCESS.getCode());
		return info;
	}

	public static RtnInfo success(Object data) {
		RtnInfo info = new RtnInfo();
		info.setRtnCode(ReturnCodes.SUCCESS.getCode());
		info.setData(data);
		return info;
	}

	public static RtnInfo error(ReturnCodes code) {
		RtnInfo info = new RtnInfo();
		info.setRtnCode(code.getCode());
		info.setRtnMsg(code.getMsg());
		info.setRtnTip(code.getDetail());
		return info;
	}

	public static RtnInfo error(ReturnCodes code, String msg) {
		RtnInfo info = new RtnInfo();
		info.setRtnCode(code.getCode());
		info.setRtnMsg(msg);
		info.setRtnTip(code.getDetail());
		return info;
	}

	/**
	 * @param code
	 * @param message
	 * @param detailMessage
	 * @return
	 */
	public static RtnInfo error(String code, String message, String detailMessage) {
		RtnInfo info = new RtnInfo();
		info.setRtnCode(code);
		info.setRtnMsg(message);
		info.setRtnTip(detailMessage);
		return info;
	}

	public static RtnInfo error(Object data, ReturnCodes code) {
		RtnInfo info = new RtnInfo();
		info.setData(data);
		info.setRtnCode(code.getCode());
		info.setRtnMsg(code.getMsg());
		info.setRtnTip(code.getDetail());
		return info;
	}
}
